package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysJobService;
import com.seahorse.youliao.service.entity.SysJobDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysJobQueryVO;
import com.seahorse.youliao.vo.response.SysJobPageInfoVO;
import com.seahorse.youliao.vo.response.SysJobResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 岗位信息表
* @author : songqiang
* @date: 2020-01-17 09:23:44.813
**/
@RestController
@Api("SysJobController")
@RequestMapping("sysJob")
@Validated
public class SysJobController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysJobController.class);
    
	@Autowired
    private SysJobService sysJobService;
    /**
     * 分页查询
     * @param sysJobQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysJobPageInfoVO selectPageList(@RequestBody @Valid SysJobQueryVO sysJobQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysJobQueryVO.toString());
        LOGGER.info(info);
        SysJobDTO sysJob = BeanUtil.convert(sysJobQueryVO, SysJobDTO.class);

        Page<SysJobResponseVO> page = PageHelper.startPage(sysJobQueryVO.getPageNum(), sysJobQueryVO.getPageSize());
        List<SysJobDTO> sysJobList = sysJobService.getList(sysJob);
        SysJobPageInfoVO sysJobPageInfo = new SysJobPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysJobPageInfo);
        List<SysJobResponseVO> voList = BeanUtil.convert(sysJobList, SysJobResponseVO.class);
        sysJobPageInfo.setList(voList);

        return sysJobPageInfo;
    }


}
